#include "gamemainfunction.h"
#include"mainwindow.h"
#include <time.h>
#include<QApplication>
#include<iostream>
#include<vector>
#include<QTimer>

using namespace std;

GameMainFunction::GameMainFunction()
{
   black=1; //黑棋
   white=-1; //白棋
   state=0; //空
}


void GameMainFunction::startgame(char type)
{
    clear();
    player=true;
    if(type=='s'||type=='j')
    {
        clear2();
    }
}


void GameMainFunction::clear(){
    //数组初始化置0
    for(int i=0 ; i < BOARD_GARD_SIZE ; i++){
        for(int j=0;j<BOARD_GARD_SIZE;j++){
            Board[i][j]=0;
        }
    }

}

//落完子后把落子处的x，y更新一下
void GameMainFunction::updateMap(int x,int y){
    if(player)  //根据下棋方填充数组
    {
        Board[x][y]=1;
    }
    else
    {
         Board[x][y]=-1;
    }

    //进行换手操作
    player=!player;
}

//实现传入坐标落子功能
void GameMainFunction::actionByPerson(int x, int y)
{
    updateMap(x,y); //重绘
}


void GameMainFunction::actionByAI(int &clickX,int &clickY)
{
    //利用计分函数实现对全棋盘的计分（暂未实现） 2022.3.20
    getScore();

    //记录最大值的位置，若有多个点，记录最后一个搜索到的点
    int maxScore = 0;
    //使用vector容器放最大值所在位置
    vector<pair<int, int>> maxPoints;  //pair函数可以将两个数据并成一个数据，make_pair函数可以创建新对象
    //利用双层循环遍历棋盘所有位置来找到评分的最大值
    for (int row = 0; row < BOARD_GARD_SIZE; row++)
        for (int col = 0; col < BOARD_GARD_SIZE; col++)
        {
            //要保证此位置
            if (Board[row][col] == 0)
            {
                if (score[row][col] > maxScore)          // 找最大的数和坐标
                {
                    maxPoints.clear();       //发现新的最大值，清空容器内之前存储的所有元素
                    maxScore = score[row][col];
                    maxPoints.push_back(make_pair(row, col));  //放入最新的最大值坐标
                }
                else if (score[row][col] == maxScore)     // 如果有多个最大的数，都放到容器中
                    maxPoints.push_back(make_pair(row, col));
            }
        }

    // 随机落子，如果有多个点的话
    srand((unsigned)time(0)); //种下启动种子，time0指根据时间来取随机值
    int index = rand() % maxPoints.size(); //随机下标，范围在容器容量内

    pair<int, int> pointPair = maxPoints.at(index);  //取出该位置元素
    //进行赋值操作
    clickX = pointPair.first;
    clickY = pointPair.second;

    //更新棋盘数组
    updateMap(clickX,clickY);
}

//实现AI落子功能，但要注意，AI操作要在落子前进行棋盘分数计算
void GameMainFunction::playAIAI(int &clickx,int &clicky)
{
      getScore();  //计分

      actionByAI(clickx,clicky);  //落子

}

//实现每落一子判断游戏输赢功能
bool GameMainFunction::isWin(int clickX,int clickY)
{
    for (int i = 0; i < 6; i++)
    {
        //往上移动六次，每一次都向下边查五个位置
         if (clickY - i >= 0 &&
            clickY - i + 5 < BOARD_GARD_SIZE &&
            Board[clickX][clickY - i] == Board[clickX][clickY - i + 1] &&
            Board[clickX][clickY - i] == Board[clickX][clickY - i + 2] &&
            Board[clickX][clickY - i] == Board[clickX][clickY - i + 3] &&
            Board[clickX][clickY - i] == Board[clickX][clickY - i + 4] &&
            Board[clickX][clickY - i] == Board[clickX][clickY - i + 5])  //竖直方向
         {
           return true;
         }
         //往左移动6次，每一次都向右边查5个位置
         else if (clickX - i >= 0 && //向左边移动的过程中不能超出左边界
             clickX - i + 5 < BOARD_GARD_SIZE && //向右边查的时候也不能超界
             Board[clickX - i][clickY] == Board[clickX - i + 1][clickY] &&
             Board[clickX - i][clickY] == Board[clickX - i + 2][clickY] &&
             Board[clickX - i][clickY] == Board[clickX - i + 3][clickY] &&
             Board[clickX - i][clickY] == Board[clickX - i + 4][clickY] &&
             Board[clickX - i][clickY] == Board[clickX - i + 5][clickY])  //水平方向
         {
             return true;
         }
         else if(clickX+i<BOARD_GARD_SIZE&&clickX+i-5>=0&&clickY-i>=0&&clickY-i+5<BOARD_GARD_SIZE&&
                 Board[clickX+i][clickY-i]==Board[clickX+i-1][clickY-i+1]&&
                 Board[clickX+i][clickY-i]==Board[clickX+i-2][clickY-i+2]&&
                 Board[clickX+i][clickY-i]==Board[clickX+i-3][clickY-i+3]&&
                 Board[clickX+i][clickY-i]==Board[clickX+i-4][clickY-i+4]&&
                 Board[clickX+i][clickY-i]==Board[clickX+i-5][clickY-i+5])  //斜向左下
         {
             return true;
         }
         else if (clickX - i >= 0 &&
                  clickX - i + 5 < BOARD_GARD_SIZE &&
                  clickY - i >= 0 &&
                  clickY - i + 5 < BOARD_GARD_SIZE &&
                  Board[clickX - i][clickY - i] == Board[clickX - i + 1][clickY - i + 1] &&
                  Board[clickX - i][clickY - i] == Board[clickX - i + 2][clickY - i + 2] &&
                  Board[clickX - i][clickY - i] == Board[clickX - i + 3][clickY - i + 3] &&
                  Board[clickX - i][clickY - i] == Board[clickX - i + 4][clickY - i + 4]&&
                  Board[clickX - i][clickY - i] == Board[clickX - i + 5][clickY - i + 5]) //斜向右下
              {
                  return true;
              }

    }
    return false;
}

//实现判断是否和棋功能，当棋盘全部被下满后，进行和棋操作（返回true）
bool GameMainFunction::isPeace()
{
    //利用双层循环遍历棋盘的每一个位置若棋盘每个位置全填满棋子，board为1，则可以和棋
    for(int i = 0 ; i < BOARD_GARD_SIZE ; i++)
    {
        for(int j = 0 ; j < BOARD_GARD_SIZE ; j++)
        {
            if(Board[i][j] == 0)
            {
                return false;
            }
        }
    }
    return true;
}

//实现四四禁手和五五禁手功能
//禁手只需对黑棋判断，无需对白棋判断
bool GameMainFunction::isBanAction(int x,int y)
{
    //利用k来记录目前有几颗棋子连起来
    int k = 0;
    //利用num来记录有几次四子或五子连起来，如果num达到2，直接可以返回true，即已经形成四四禁手或者五五禁手
    int num = 0;

    //向下找六个位置
    for(int i = 0 ; i < 6 ;i++) //连续判断六个位置
    {
        if(y + i < BOARD_GARD_SIZE) //确保不会超出棋盘
        {
            if(Board[x][y+i] == 1) //找到黑子
            {
                k++;
            }
            else if(Board[x][y+i] == -1)
            {
                break; //遇到了不符合的白棋子，可以退出循环
            }
        }
        else //如果准备超出棋盘，直接break出循环
        {
            break;
        }
    }

    if(k >= 4)
    {
        num++;
    }
    if(num >= 2)
    {
        return true;
    }
    //每一个方向判断结束后记得清零k的次数，为下一个方向做好准备
    k=0;

    //向上找六个位置
    for(int i = 0 ; i < 6 ; i++)
    {
        if(y - i >= 0) //确保不会超出棋盘
        {
            if(Board[x][y-i] == 1) //找到黑子
            {
                k++;
            }
            else if(Board[x][y-i] == -1)
            {
                break; //遇到了不符合的白棋子，可以退出循环
            }
        }
        else //如果准备超出棋盘，直接break出循环
        {
            break;
        }
    }
    if(k>=4)
    {
        num++;
    }
    if(num>=2)
    {
        return true;
    }
    //每一个方向判断结束后记得清零k的次数，为下一个方向做好准备
    k=0;

    //向左找六个位置
    for(int i = 0 ; i < 6 ; i++)
    {
        if(x - i >= 0) //确保不会超出棋盘
        {
            if(Board[x-i][y] == 1) //找到黑子
            {
                k++;
            }
            else if(Board[x-i][y] == -1)
            {
                break; //遇到了不符合的白棋子，可以退出循环
            }
        }
        else //如果准备超出棋盘，直接break出循环
        {
            break;
        }
    }
    if(k >= 4)
    {
        num++;
    }
    if(num >= 2)
    {
        return true;
    }
    //每一个方向判断结束后记得清零k的次数，为下一个方向做好准备
    k=0;

    //向右找六个位置
    for(int i = 0 ; i < 6 ; i++)
    {
        if( x + i < BOARD_GARD_SIZE) //确保不会超出棋盘
        {
            if(Board[x+i][y] == 1) //找到黑子
            {
                k++;
            }
            else if(Board[x+i][y]==-1)
            {
                break; //遇到了不符合的白棋子，可以退出循环
            }
        }
        else //如果准备超出棋盘，直接break出循环
        {
            break;
        }
    }
    if(k>=4)
    {
        num++;
    }
    if(num>=2)
    {
        return true;
    }
    //每一个方向判断结束后记得清零k的次数，为下一个方向做好准备
    k=0;

    //向左上
    for(int i = 0 ; i < 6 ; i++)
    {
        if( x - i >= 0 && y - i >= 0) //确保不会超出棋盘
        {
            if(Board[x-i][y-i] == 1) //找到黑子
            {
                k++;
            }
            else if(Board[x-i][y-i] == -1) //遇到了不符合的白棋子，可以退出循环
            {
                break;
            }
        }
        else
        {
            break; //如果准备超出棋盘，直接break出循环
        }
    }
    if(k >= 4)
    {
        num++;
    }
    if(num >= 2)
    {
        return true;
    }
    //每一个方向判断结束后记得清零k的次数，为下一个方向做好准备
    k=0;

    //向左下
    for(int i = 0 ; i < 6 ; i++)
    {
        if(x - i >= 0 && y + i < BOARD_GARD_SIZE) //确保不会超出棋盘
        {
            if(Board[x-i][y+i] == 1) //找到黑子
            {
                k++;
            }
            else if(Board[x-i][y+i] == -1) //遇到了不符合的白棋子，可以退出循环
            {
                break;
            }
        }
        else
        {
            break; //如果准备超出棋盘，直接break出循环
        }
    }
    if(k >= 4)
    {
        num++;
    }
    if(num >= 2)
    {
        return true;
    }
    //每一个方向判断结束后记得清零k的次数，为下一个方向做好准备
    k=0;

    //向右上方向查六个位置
    for(int i = 0 ; i < 6 ; i++)
    {
        if(x + i < BOARD_GARD_SIZE && y - i >= 0) //确保不会超出棋盘
        {
            if(Board[x+i][y-i] == 1) //找到黑子
            {
                k++;
            }
            else if(Board[x+i][y-i] == -1) //遇到了不符合的白棋子，可以退出循环
            {
                break;
            }
        }
        else
        {
            break; //如果准备超出棋盘，直接break出循环
        }
    }
    if(k >= 4)
    {
        num++;
    }
    if(num >= 2)
    {
        return true;
    }
    //每一个方向判断结束后记得清零k的次数，为下一个方向做好准备
    k=0;

    //向右下方向查六个位置
    for(int i = 0 ; i < 6 ; i++)
    {
        if(x + i < BOARD_GARD_SIZE && y + i < BOARD_GARD_SIZE) //确保不会超出棋盘
        {
            if(Board[x+i][y+i] == 1) //找到黑子
            {
                k++;
            }
            else if(Board[x+i][y+i] == -1 ) //遇到了不符合的白棋子，可以退出循环
            {
                break;
            }
        }
        else
        {
            break; //如果准备超出棋盘，直接break出循环
        }
    }
    if(k >= 4)
    {
        num++;
    }
    if(num >= 2)
    {
        return true;
    }

    //如果将所有方向所有情况都查完，没有找到禁手的情况，则可以返回false
    return false;
}


//核心功能：实现对棋盘每个位置的计分
//分别求各位置两种棋子的权值，取最大值位置为最佳落子点
void GameMainFunction::getScore()
{
    //活五>死五>活四>活三>死四>活二>死三>死二>其他
    //分别求各位置两种棋子的加权值，取最大值位置为最佳落子点
    int value=0;
    int value2=0;
    int flag=-1;   //白子
    int flag2=1;    //黑子

    //先把分数棋盘清零
    clear2();

    //利用双层循环遍历棋盘的每一个位置
    for(int clickx = 0 ; clickx < BOARD_GARD_SIZE ; clickx++)
    {
        for(int clicky = 0 ; clicky < BOARD_GARD_SIZE ; clicky++)
        {
            if(Board[clickx][clicky] != 0) continue;//如果此位置已经有棋子，直接跳过该棋子，判断下一个棋子

            //计分前先初始化分数，以免被上一次结果干扰
            value = 0; //用于进攻（想办法将自己连成六个）
            value2 = 0;//用于破坏（想办法破坏对手连成六个）

            //利用双层循环来计算已锁定位置的周围八个位置以及自身位置（共九个）的分数
            for(int i = -1 ; i <= 1 ; i++)
            {
                for(int j = -1 ; j <= 1 ; j++)
                {
                    //活五
                    if(clickx+6*i>=0&&clickx+6*i<BOARD_GARD_SIZE&&clicky+6*j>=0&&clicky+6*j<BOARD_GARD_SIZE&&clickx+5*i>=0&&clicky+5*j>=0&&clickx+4*i>=0&&clicky+4*j>=0
                            &&clickx+3*i>=0&&clicky+3*j>=0&&clickx+2*i>=0&&clicky+2*j>=0&&clickx+i>=0
                            &&clicky+j>=0&&clickx+5*i<BOARD_GARD_SIZE&&clicky+5*j<BOARD_GARD_SIZE&&clickx+4*i<BOARD_GARD_SIZE&&clicky+4*j<BOARD_GARD_SIZE
                            &&clickx+3*i<BOARD_GARD_SIZE&&clicky+3*j<BOARD_GARD_SIZE&&clickx+2*i<BOARD_GARD_SIZE&&clicky+2*j<BOARD_GARD_SIZE&&clickx+i<BOARD_GARD_SIZE
                            &&clicky<BOARD_GARD_SIZE&&Board[clickx+i*1][clicky+j*1]==flag
                            &&Board[clickx+i*2][clicky+j*2]==flag&&Board[clickx+i*3][clicky+j*3]==flag
                            &&Board[clickx+i*4][clicky+j*4]==flag&&Board[clickx+i*5][clicky+j*5]==flag&&Board[clickx+i*6][clicky+j*6]==0) //活五
                    {
                        value+=600000;
                    }
                    else if(clickx+6*i>=0&&clickx+6*i<BOARD_GARD_SIZE&&clicky+6*j>=0&&clicky+6*j<BOARD_GARD_SIZE&&clickx+5*i>=0&&clicky+5*j>=0&&clickx+4*i>=0&&clicky+4*j>=0
                            &&clickx+3*i>=0&&clicky+3*j>=0&&clickx+2*i>=0&&clicky+2*j>=0&&clickx+i>=0
                            &&clicky+j>=0&&clickx+5*i<BOARD_GARD_SIZE&&clicky+5*j<BOARD_GARD_SIZE&&clickx+4*i<BOARD_GARD_SIZE&&clicky+4*j<BOARD_GARD_SIZE
                            &&clickx+3*i<BOARD_GARD_SIZE&&clicky+3*j<BOARD_GARD_SIZE&&clickx+2*i<BOARD_GARD_SIZE&&clicky+2*j<BOARD_GARD_SIZE&&clickx+i<BOARD_GARD_SIZE
                            &&clicky<BOARD_GARD_SIZE&&Board[clickx+i*1][clicky+j*1]==flag
                            &&Board[clickx+i*2][clicky+j*2]==flag&&Board[clickx+i*3][clicky+j*3]==flag
                            &&Board[clickx+i*4][clicky+j*4]==flag&&Board[clickx+i*5][clicky+j*5]&&Board[clickx+i*6][clicky+j*6]==1)   //死五
                    {
                        value+=500000;
                    }
                    else if(clickx+5*i>=0&&clicky+5*j>=0&&clickx+4*i>=0&&clicky+4*j>=0
                            &&clickx+3*i>=0&&clicky+3*j>=0&&clickx+2*i>=0&&clicky+2*j>=0&&clickx+i>=0
                            &&clicky+j>=0&&clickx+5*i<BOARD_GARD_SIZE&&clicky+5*j<BOARD_GARD_SIZE&&clickx+4*i<BOARD_GARD_SIZE&&clicky+4*j<BOARD_GARD_SIZE
                            &&clickx+3*i<BOARD_GARD_SIZE&&clicky+3*j<BOARD_GARD_SIZE&&clickx+2*i<BOARD_GARD_SIZE&&clicky+2*j<BOARD_GARD_SIZE&&clickx+i<BOARD_GARD_SIZE
                            &&clicky<BOARD_GARD_SIZE&&Board[clickx+i*1][clicky+j*1]==flag
                            &&Board[clickx+i*2][clicky+j*2]==flag&&Board[clickx+i*3][clicky+j*3]==flag
                            &&Board[clickx+i*4][clicky+j*4]==flag&&Board[clickx+i*5][clicky+j*5]==0)  //活四
                    {
                        value+=400000;
                    }
                    else if(clickx+5*i>=0&&clicky+5*j>=0&&clickx+4*i>=0&&clicky+4*j>=0
                            &&clickx+3*i>=0&&clicky+3*j>=0&&clickx+2*i>=0&&clicky+2*j>=0&&clickx+i>=0
                            &&clicky+j>=0&&clickx+5*i<BOARD_GARD_SIZE&&clicky+5*j<BOARD_GARD_SIZE&&clickx+4*i<BOARD_GARD_SIZE&&clicky+4*j<BOARD_GARD_SIZE
                            &&clickx+3*i<BOARD_GARD_SIZE&&clicky+3*j<BOARD_GARD_SIZE&&clickx+2*i<BOARD_GARD_SIZE&&clicky+2*j<BOARD_GARD_SIZE&&clickx+i<BOARD_GARD_SIZE
                            &&clicky<BOARD_GARD_SIZE&&Board[clickx+i*1][clicky+j*1]==flag
                            &&Board[clickx+i*2][clicky+j*2]==flag&&Board[clickx+i*3][clicky+j*3]==flag
                            &&Board[clickx+i*4][clicky+j*4]==flag&&Board[clickx+i*5][clicky+j*5]==1)  //死四
                    {
                        value+=250000;
                    }
                    else if(clickx+4*i>=0&&clicky+4*j>=0
                            &&clickx+3*i>=0&&clicky+3*j>=0&&clickx+2*i>=0&&clicky+2*j>=0&&clickx+i>=0
                            &&clicky+j>=0&&clickx+4*i<BOARD_GARD_SIZE&&clicky+4*j<BOARD_GARD_SIZE
                            &&clickx+3*i<BOARD_GARD_SIZE&&clicky+3*j<BOARD_GARD_SIZE&&clickx+2*i<BOARD_GARD_SIZE&&clicky+2*j<BOARD_GARD_SIZE&&clickx+i<BOARD_GARD_SIZE
                            &&clicky<BOARD_GARD_SIZE&&Board[clickx+i*1][clicky+j*1]==flag
                            &&Board[clickx+i*2][clicky+j*2]==flag&&Board[clickx+i*3][clicky+j*3]==flag
                            &&Board[clickx+i*4][clicky+j*4]==0)  //活三
                     {
                         value+=300000;
                     }
                    else if(clickx+4*i>=0&&clicky+4*j>=0
                            &&clickx+3*i>=0&&clicky+3*j>=0&&clickx+2*i>=0&&clicky+2*j>=0&&clickx+i>=0
                            &&clicky+j>=0&&clickx+4*i<BOARD_GARD_SIZE&&clicky+4*j<BOARD_GARD_SIZE
                            &&clickx+3*i<BOARD_GARD_SIZE&&clicky+3*j<BOARD_GARD_SIZE&&clickx+2*i<BOARD_GARD_SIZE&&clicky+2*j<BOARD_GARD_SIZE&&clickx+i<BOARD_GARD_SIZE
                            &&clicky<BOARD_GARD_SIZE&&Board[clickx+i*1][clicky+j*1]==flag
                            &&Board[clickx+i*2][clicky+j*2]==flag&&Board[clickx+i*3][clicky+j*3]==flag
                            &&Board[clickx+i*4][clicky+j*4]==1)  //死三
                    {
                        value+=150000;
                    }
                    else if(clickx+3*i>=0&&clicky+3*j>=0&&clickx+2*i>=0&&clicky+2*j>=0&&clickx+i>=0
                            &&clicky+j>=0&&clickx+3*i<BOARD_GARD_SIZE&&clicky+3*j<BOARD_GARD_SIZE&&clickx+2*i<BOARD_GARD_SIZE&&clicky+2*j<BOARD_GARD_SIZE&&clickx+i<BOARD_GARD_SIZE
                            &&clicky<BOARD_GARD_SIZE&&Board[clickx+i*1][clicky+j*1]==flag
                            &&Board[clickx+i*2][clicky+j*2]==flag&&Board[clickx+i*3][clicky+j*3]==0)  //活二
                    {
                        value+=200000;
                    }
                    else if(clickx+3*i>=0&&clicky+3*j>=0&&clickx+2*i>=0&&clicky+2*j>=0&&clickx+i>=0
                            &&clicky+j>=0&&clickx+3*i<BOARD_GARD_SIZE&&clicky+3*j<BOARD_GARD_SIZE&&clickx+2*i<BOARD_GARD_SIZE&&clicky+2*j<BOARD_GARD_SIZE&&clickx+i<BOARD_GARD_SIZE
                            &&clicky<BOARD_GARD_SIZE&&Board[clickx+i*1][clicky+j*1]==flag
                            &&Board[clickx+i*2][clicky+j*2]==flag&&Board[clickx+i*3][clicky+j*3]==1)  //死二
                    {
                        value+=100000;
                    }
                    else if(clickx+1*i>=0&&clickx+1*i<BOARD_GARD_SIZE&&clicky+1*j>=0&&clicky+j*1<BOARD_GARD_SIZE&&Board[clickx+1*i][clicky+1*j]==flag)  //一个棋子
                    {
                        value+=2000;
                    }
                    else  //其他
                    {
                        value+=1000;
                    }
                }
            }

            for(int i=-1;i<=1;i++)
            {
                for(int j=-1;j<=1;j++)
                {
                    if(clickx+6*i>=0&&clickx+6*i<BOARD_GARD_SIZE&&clicky+6*j>=0&&clicky+6*j<BOARD_GARD_SIZE&&clickx+5*i>=0&&clicky+5*j>=0&&clickx+4*i>=0&&clicky+4*j>=0
                            &&clickx+3*i>=0&&clicky+3*j>=0&&clickx+2*i>=0&&clicky+2*j>=0&&clickx+i>=0
                            &&clicky+j>=0&&clickx+5*i<BOARD_GARD_SIZE&&clicky+5*j<BOARD_GARD_SIZE&&clickx+4*i<BOARD_GARD_SIZE&&clicky+4*j<BOARD_GARD_SIZE
                            &&clickx+3*i<BOARD_GARD_SIZE&&clicky+3*j<BOARD_GARD_SIZE&&clickx+2*i<BOARD_GARD_SIZE&&clicky+2*j<BOARD_GARD_SIZE&&clickx+i<BOARD_GARD_SIZE
                            &&clicky<BOARD_GARD_SIZE&&Board[clickx+i*1][clicky+j*1]==flag2
                            &&Board[clickx+i*2][clicky+j*2]==flag2&&Board[clickx+i*3][clicky+j*3]==flag2
                            &&Board[clickx+i*4][clicky+j*4]==flag2&&Board[clickx+i*5][clicky+j*5]==flag2&&Board[clickx+i*6][clicky+j*6]==0) //活五
                    {
                        value2+=600000;
                    }
                    else if(clickx+6*i>=0&&clickx+6*i<BOARD_GARD_SIZE&&clicky+6*j>=0&&clicky+6*j<BOARD_GARD_SIZE&&clickx+5*i>=0&&clicky+5*j>=0&&clickx+4*i>=0&&clicky+4*j>=0
                            &&clickx+3*i>=0&&clicky+3*j>=0&&clickx+2*i>=0&&clicky+2*j>=0&&clickx+i>=0
                            &&clicky+j>=0&&clickx+5*i<BOARD_GARD_SIZE&&clicky+5*j<BOARD_GARD_SIZE&&clickx+4*i<BOARD_GARD_SIZE&&clicky+4*j<BOARD_GARD_SIZE
                            &&clickx+3*i<BOARD_GARD_SIZE&&clicky+3*j<BOARD_GARD_SIZE&&clickx+2*i<BOARD_GARD_SIZE&&clicky+2*j<BOARD_GARD_SIZE&&clickx+i<BOARD_GARD_SIZE
                            &&clicky<BOARD_GARD_SIZE&&Board[clickx+i*1][clicky+j*1]==flag2
                            &&Board[clickx+i*2][clicky+j*2]==flag2&&Board[clickx+i*3][clicky+j*3]==flag2
                            &&Board[clickx+i*4][clicky+j*4]==flag2&&Board[clickx+i*5][clicky+j*5]==flag2&&Board[clickx+i*6][clicky+j*6]==-1)   //死五
                    {
                        value2+=500000;
                    }
                    else if(clickx+5*i>=0&&clicky+5*j>=0&&clickx+4*i>=0&&clicky+4*j>=0
                            &&clickx+3*i>=0&&clicky+3*j>=0&&clickx+2*i>=0&&clicky+2*j>=0&&clickx+i>=0
                            &&clicky+j>=0&&clickx+5*i<BOARD_GARD_SIZE&&clicky+5*j<BOARD_GARD_SIZE&&clickx+4*i<BOARD_GARD_SIZE&&clicky+4*j<BOARD_GARD_SIZE
                            &&clickx+3*i<BOARD_GARD_SIZE&&clicky+3*j<BOARD_GARD_SIZE&&clickx+2*i<BOARD_GARD_SIZE&&clicky+2*j<BOARD_GARD_SIZE&&clickx+i<BOARD_GARD_SIZE
                            &&clicky<BOARD_GARD_SIZE&&Board[clickx+i*1][clicky+j*1]==flag2
                            &&Board[clickx+i*2][clicky+j*2]==flag2&&Board[clickx+i*3][clicky+j*3]==flag2
                            &&Board[clickx+i*4][clicky+j*4]==flag2&&Board[clickx+i*5][clicky+j*5]==0)  //活五
                    {
                        value2+=400000;
                    }
                    else if(clickx+5*i>=0&&clicky+5*j>=0&&clickx+4*i>=0&&clicky+4*j>=0
                            &&clickx+3*i>=0&&clicky+3*j>=0&&clickx+2*i>=0&&clicky+2*j>=0&&clickx+i>=0
                            &&clicky+j>=0&&clickx+5*i<BOARD_GARD_SIZE&&clicky+5*j<BOARD_GARD_SIZE&&clickx+4*i<BOARD_GARD_SIZE&&clicky+4*j<BOARD_GARD_SIZE
                            &&clickx+3*i<BOARD_GARD_SIZE&&clicky+3*j<BOARD_GARD_SIZE&&clickx+2*i<BOARD_GARD_SIZE&&clicky+2*j<BOARD_GARD_SIZE&&clickx+i<BOARD_GARD_SIZE
                            &&clicky<BOARD_GARD_SIZE&&Board[clickx+i*1][clicky+j*1]==flag2
                            &&Board[clickx+i*2][clicky+j*2]==flag2&&Board[clickx+i*3][clicky+j*3]==flag2
                            &&Board[clickx+i*4][clicky+j*4]==flag2&&Board[clickx+i*5][clicky+j*5]==-1)  //死五
                    {
                        value2+=250000;
                    }
                    else if(clickx+4*i>=0&&clicky+4*j>=0
                            &&clickx+3*i>=0&&clicky+3*j>=0&&clickx+2*i>=0&&clicky+2*j>=0&&clickx+i>=0
                            &&clicky+j>=0&&clickx+4*i<BOARD_GARD_SIZE&&clicky+4*j<BOARD_GARD_SIZE
                            &&clickx+3*i<BOARD_GARD_SIZE&&clicky+3*j<BOARD_GARD_SIZE&&clickx+2*i<BOARD_GARD_SIZE&&clicky+2*j<BOARD_GARD_SIZE&&clickx+i<BOARD_GARD_SIZE
                            &&clicky<BOARD_GARD_SIZE&&Board[clickx+i*1][clicky+j*1]==flag2
                            &&Board[clickx+i*2][clicky+j*2]==flag2&&Board[clickx+i*3][clicky+j*3]==flag2
                            &&Board[clickx+i*4][clicky+j*4]==0)  //活三
                     {
                         value2+=300000;
                     }
                    else if(clickx+4*i>=0&&clicky+4*j>=0
                            &&clickx+3*i>=0&&clicky+3*j>=0&&clickx+2*i>=0&&clicky+2*j>=0&&clickx+i>=0
                            &&clicky+j>=0&&clickx+4*i<BOARD_GARD_SIZE&&clicky+4*j<BOARD_GARD_SIZE
                            &&clickx+3*i<BOARD_GARD_SIZE&&clicky+3*j<BOARD_GARD_SIZE&&clickx+2*i<BOARD_GARD_SIZE&&clicky+2*j<BOARD_GARD_SIZE&&clickx+i<BOARD_GARD_SIZE
                            &&clicky<BOARD_GARD_SIZE&&Board[clickx+i*1][clicky+j*1]==flag2
                            &&Board[clickx+i*2][clicky+j*2]==flag2&&Board[clickx+i*3][clicky+j*3]==flag2
                            &&Board[clickx+i*4][clicky+j*4]==-1)  //死三
                    {
                        value2+=150000;
                    }
                    else if(clickx+3*i>=0&&clicky+3*j>=0&&clickx+2*i>=0&&clicky+2*j>=0&&clickx+i>=0
                            &&clicky+j>=0&&clickx+3*i<BOARD_GARD_SIZE&&clicky+3*j<BOARD_GARD_SIZE&&clickx+2*i<BOARD_GARD_SIZE&&clicky+2*j<BOARD_GARD_SIZE&&clickx+i<BOARD_GARD_SIZE
                            &&clicky<BOARD_GARD_SIZE&&Board[clickx+i*1][clicky+j*1]==flag2
                            &&Board[clickx+i*2][clicky+j*2]==flag2&&Board[clickx+i*3][clicky+j*3]==0)  //活二
                    {
                        value2+=200000;
                    }
                    else if(clickx+3*i>=0&&clicky+3*j>=0&&clickx+2*i>=0&&clicky+2*j>=0&&clickx+i>=0
                            &&clicky+j>=0&&clickx+3*i<BOARD_GARD_SIZE&&clicky+3*j<BOARD_GARD_SIZE&&clickx+2*i<BOARD_GARD_SIZE&&clicky+2*j<BOARD_GARD_SIZE&&clickx+i<BOARD_GARD_SIZE
                            &&clicky<BOARD_GARD_SIZE&&Board[clickx+i*1][clicky+j*1]==flag2
                            &&Board[clickx+i*2][clicky+j*2]==flag2&&Board[clickx+i*3][clicky+j*3]==-1)  //死二
                    {
                        value2+=100000;
                    }
                    else if(clickx+1*i>=0&&clickx+1*i<BOARD_GARD_SIZE&&clicky+1*j>=0&&clicky+j*1<BOARD_GARD_SIZE&&Board[clickx+1*i][clicky+1*j]==flag2)  //一个棋子
                    {
                        value2+=2000;
                    }
                    else        //其他
                    {
                        value2+=1000;
                    }
                }
            }
            score[clickx][clicky] = max(value,value2);

        }
    }
}


//实现“计分棋盘”清零操作
void GameMainFunction::clear2()
{
    //利用双层循环遍历棋盘的每一个位置
    for(int i = 0 ; i < BOARD_GARD_SIZE ; i++)
    {
        for(int j = 0 ; j < BOARD_GARD_SIZE ; j++)
        {
            score[i][j] = 0;
        }
    }
}

